﻿/*
 * Cratos Tools - General
 * Cratos Entity Paging Collection Base class
 * 
 * Copyright (c) 2011-2012 Draco
 * 
 * This file is part of Cratos.
 * 
 * Cratos is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * Cratos is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Cratos.  If not, see <http://www.gnu.org/licenses/>.
 * 
 *       .==.        .==.
 *      //'^\\      //^'\\
 *     // ^ ^\(\__/)/^ ^^\\
 *    //^ ^^ ^/6  6\ ^^ ^ \\
 *   //^ ^^ ^/( .. )\^ ^ ^ \\
 *  // ^^ ^/\| V""V|/\^ ^ ^ \\
 * //^^/\/ /  '~~'  \ \/\^ ^ \\
 *  ------------------------------------
 *  HERE BE DRAGONS
 *  
 *  Johan Dercksen - johan@draco.co.za
 */
using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Collections.ObjectModel;

using Cratos.Tools.General;

namespace Cratos.Server.Entity
{
	/// <summary>
	/// Cratos Entity Collection Base class
	/// </summary>
	/// <typeparam name="T"></typeparam>
	public abstract class CratosEntityPagingCollectionBase<T> : CratosCollectionBase<T>, ICratosEntityPagingCollectionAccess<T> where T : IDOCratos, new()
	{
		#region Class Constant declarations
		#endregion

		#region Class Event declarations
		/// <summary>
		/// New Page event
		/// </summary>
		public event EntityCollectionNewPageEventHandler NewPage;

		/// <summary>
		/// Error Event
		/// </summary>
		public event EntityCollectionErrorEventHandler Error;

		/// <summary>
		/// Error Event
		/// </summary>
		public event EntityCollectionCompletedEventHandler Completed;
		#endregion

		#region Class Variable declarations
		#endregion

		#region Class Constructors & Destructors
		/// <summary>
		/// Class Constructor
		/// </summary>
		public CratosEntityPagingCollectionBase() : base() { }
		#endregion

		#region Class Properties
		/// <summary>
		/// New Page event handler
		/// </summary>
		/// <param name="pageNo">Page Number</param>
		/// <param name="doCollection">Data Object Collection</param>
		protected void OnNewPage(long pageNo, Collection<IDOCratos> doCollection)
		{
			// Declare the required variables

			// Raise the relevant event if required
			if (this.NewPage != null) { this.NewPage(pageNo, doCollection); }

			// Return to calling method
			return;
		}

		/// <summary>
		/// New Page event handler
		/// </summary>
		/// <param name="errorCollection">Error Collection</param>
		protected void OnError(Collection<CratosError> errorCollection)
		{
			// Declare the required variables

			// Raise the relevant event if required
			if (this.Error != null) { this.Error(errorCollection); }

			// Return to calling method
			return;
		}

		/// <summary>
		/// Completed event handler
		/// </summary>
		/// <param name="actionResult">Cratos Action result</param>
		/// <param name="doCollection">Data Object Collection</param>
		protected void OnCompleted(DOCratosActionResult actionResult, Collection<IDOCratos> doCollection)
		{
			// Declare the required variables

			// Raise the relevant event if required
			if (this.Completed != null) { this.Completed(actionResult, doCollection); }

			// Return to calling method
			return;
		}
		#endregion

		#region Class Methods
		/// <summary>
		/// Entity Perform Action (Paging)
		/// </summary>
		/// <returns>A Boolean indicating success of the method</returns>
		public abstract bool PerformAction(IDOCratosPagingCollection<T> cratosDOCollection);
		#endregion

		#region Class Support Methods
		#endregion
	}
}
